'use strict';

    angular.module('app')
        .controller('deviceDetailController', ['$scope', '$rootScope', '$state', '$timeout', 'toaster',
        function($scope, $rootScope, $state, $timeout, toaster) {
       $scope.loading = false;
        $scope.title="设备详情";
        var id = $state.params.id;
        var onlineStatus = $state.params.onlineStatus;
        activate(id,onlineStatus);
        //将所有的input，select标签弄成不可编辑
		$("input").attr("disabled",true);
		$("select").attr("disabled",true);
      
        $scope.selUser = function(){
        	$scope.record.personId=$scope.record.person.split('_')[0];
        	$scope.record.cardNo=$scope.record.person.split('_')[1];
        }
        // 初始化页面
        function activate(id) {
        	console.log(id)
	        $scope.loading = true;
        	$.ajax({
        		type: 'POST',
	            dataType: 'json',
				contentType:'application/json;charset=UTF-8',
				url : '/dac/dm/dmManager/deviceInfo',
				data: angular.toJson({'id': id})
			}).then(function(result) {
		        $scope.loading = false;
		        console.log(result);
				if (result.httpCode == 200) {
					$scope.record = result.data;
//					$scope.record.onlineStatus = onlineStatus;
					var abilities = $scope.record.abilities;
					var arr = [];
					arr = abilities.split(",");
					var abilityInput = $('input[type="checkbox"]');
					
						for (var j = 0; j < arr.length; j++) {
							if($(abilityInput[arr[j]]).attr('data-code')==arr[j]){
								$("#A"+arr[j]+"").attr("checked", true);
							}
						}
						
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
        }
        
    }]);